package test.groovy

class MaxRetriesExtension {
    static String greeting2(String self) {
        'Hello, world2!'
    }

    static String greeting(String self) {
        'MaxRetriesExtension Hello, world!'
    }

    static void maxRetries(Integer self, Closure code) {
        int retries = 0
        Throwable e
        while (retries < self) {
            try {
                code.call()
                break
            } catch (Throwable err) {
                e = err
                retries++
            }
        }
        if (retries == 0 && e) {
            throw e
        }
    }
}